package com.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.pojo.Stock;
import com.example.service.StockService;
import com.example.mapper.StockMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author Xiri
* @description 针对表【stock】的数据库操作Service实现
* @createDate 2025-07-03 13:20:15
*/
@Service
public class StockServiceImpl extends ServiceImpl<StockMapper, Stock>
    implements StockService{
	
	@Override
	public void reduce(Integer id,Integer num) 
	{
		Stock stock = this.getById(id);
		Integer amount = stock.getAmount();
		if(amount<num || amount == 0)
			throw new RuntimeException("库存不足");
		amount-=num;
		stock.setAmount(amount);
		this.updateById(stock);
	}
}




